package tcc.model.colony;

import java.util.ArrayList;
import java.util.List;

import tcc.model.graph.Edge;
import tcc.model.graph.Vertex;

/**
 * Represents a Ant and your possible actions
 * @author Gabriel Pacheco
 *
 */
public class Ant {
	private final double alpha = 1; 
	private final double betha = 1; 
	private final double n = 1;
	private final double releasePheromoneTax = 3;

	private Vertex actualVertex = null;
	private List<Edge> route = new ArrayList<Edge>();
	private double distance = 0;
	
	public Ant (Vertex startVertex) {
		this.actualVertex = startVertex;
	}
	
	public void addEdgeToRoute(Edge e) {
		this.route.add(e);
	}
	
	public List<Edge> getRoute () {
		return this.route;
	}
	
	public Vertex getActualVertex() {
		return actualVertex;
	}

	public void setActualVertex(Vertex actualVertex) {
		this.actualVertex = actualVertex;
	}
	
	public double getDistance() {
		return this.distance;
	}

	public void increaseDistance(double distance) {
		this.distance += distance;
	}
	
	public void clearDistance() { 
		this.distance = 0;
	}

	/**
	 * 
	 * @param e Target Edge
	 * @param v Actual Vertex
	 * 
	 * Calculates the probability of an ant go in a given edge
	 */
	public double edgeProbability (Edge e, Vertex v) { //FIXME PARAMETERS
		double probability = 0;
		double neighborhood = 0;
		
		for(Edge neighbors : v.getEdges()) {
			neighborhood += (Math.pow(neighbors.getPheromone(), this.alpha) * Math.pow(this.n, this.betha) );
		}
		
		probability = (Math.pow(e.getPheromone(), this.alpha) * Math.pow(this.n, this.betha) ) / neighborhood; 
		
		//probability = (Math.pow(e.getPheromone(), ths.alpha) * Math.pow(1/e.getDistance(), this.betha) ) / neighborhood;
	
		return probability;
	}
	
	/**
	 * Define the quantity of pheromone released by ant on a determined edge
	 * @param e Edge that will receive the pheromone
	 * @return quantity of pheromone released
	 */
	public double releasePheromone(Edge e) {
		return this.releasePheromoneTax / e.getDistance();
	}
}
